<template>
  <div class="diy_table">
    <div class="table_header">
      <div
        v-for="item in column"
        :key="item.id"
        class="common_td header_td"
        diy
        :isempty="item.new"
      >
        <diyHeader :data="item">
          <template #target="{ data }">
            <slot name="target" :data="data"></slot>
          </template>
        </diyHeader>
      </div>
    </div>
    <div class="table_body" @scroll="$emit('handleScroll')">
      <div v-for="(item, index) in trLength" class="common_tr" :key="index">
        <div class="common_td" v-for="it in column" :key="it.id">
          <template v-if="it.basic">
            <div class="inner_td">
              <div class="common_card">
                <span
                  :class="[item.isPri ? 'primary' : 'follow', 'circle']"
                ></span
                >{{ index + 1 }}
              </div>
            </div>
          </template>
          <template v-else-if="it.new">
            <div class="inner_td">
              <div class="common_card"></div>
            </div>
          </template>
          <template v-else>
            <template
              v-for="(pnItem, pnIndex) in tableDataMap[it.left.pnNumber][
                `${index + 1}`
              ]"
            >
              <div class="inner_td" :key="pnIndex">
                <diyContent class="common_card" :data="pnItem"></diyContent>
              </div>
              <div
                class="merge"
                :key="pnIndex + 'merge'"
                v-if="
                  pnIndex !=
                  tableDataMap[it.left.pnNumber][`${index + 1}`].length - 1
                "
              >
                <div class="blue_line" v-if="isMerge">
                  <el-tooltip
                    effect="dark"
                    content="合并特征"
                    placement="top"
                    :open-delay="300"
                  >
                    <div class="merge_circle"></div>
                  </el-tooltip>
                </div>
              </div>
            </template>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import diyHeader from "./tableComponent/diyHeader.vue";
import diyContent from "./tableComponent/diyContent.vue";
export default {
  props: {
    column: {
      type: Array,
      default: () => [],
    },
    trLength: {
      type: Number,
      default: 0,
    },
    tableDataMap: {
      type: Object,
      default: () => ({}),
    },
    td_width: {
      type: String,
      default: "420px",
    },
    isMerge: {
      type: Boolean,
      default: false,
    },
  },
  components: {
    diyHeader,
    diyContent,
  },
  watch: {
    td_width: {
      handler(val) {
        //除了第一列以外的列都要设置固定宽度  为了固定表格列position_div使用
        this.$el.style.setProperty("--td-width", `${this.td_width}`);
      },
    },
  },
  mounted() {
    this.$el.style.setProperty("--td-width", `${this.td_width}`);
  },
};
</script>
<style scoped lang="less">
div {
  box-sizing: border-box;
}
.diy_table {
  max-width: 100%;
  max-height: 100%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
}
.common_td {
  min-height: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 8px;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  &:nth-last-of-type(1) {
    border-right: none;
  }
  &:nth-of-type(1) {
    width: 104px;
  }
  &:nth-of-type(n + 2) {
    min-width: 420px;
    width: var(--td-width);
    flex-shrink: 0;
  }
}
.table_header {
  display: flex;
  overflow: auto;
  flex-shrink: 0;
  padding-right: 8px;
  &::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
  .header_td {
    padding: 14px 5px;
    font-weight: 600;
    font-size: 12px;
    color: #626262;
    line-height: 20px;
  }
}
.table_body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.common_tr {
  display: flex;
  & > .common_td:nth-of-type(n + 2) .common_card:hover {
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.16);
  }
  & > .common_td:nth-of-type(1) {
    .common_card {
      flex-direction: row;
      align-items: center;
    }
  }
  .inner_td {
    width: 100%;
    height: 100%;
    &:nth-last-of-type(1) {
      padding-bottom: 8px;
    }
    .common_card {
      width: 100%;
      height: 100%;
      background: #ffffff;
      border-radius: 4px;
      background-color: #fff;
      padding: 16px;
      font-size: 14px;
      color: #181818;
      line-height: 22px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .circle {
        width: 10px;
        height: 10px;
        display: inline-block;
        border-radius: 50%;
        margin-right: 6px;
      }
      .primary {
        background: #1c4cba;
      }
      .follow {
        background: #a3a3a3;
      }
    }
  }
  .merge {
    width: 100%;
    height: 8px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    &:hover .blue_line {
      display: block;
    }
    .blue_line {
      width: 100%;
      height: 4px;
      background: #1c4cba;
      display: none;
      transition: 0.3s;
      position: relative;
    }
    .merge_circle {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      position: absolute;
      background: #1c4cba;
      left: calc(50% - 14px);
      top: calc(50% - 14px);
    }
  }
}
</style>
